#include <stdio.h>
#include "file.h"


// 初始化历史操作文件
void on_history_file_init(manager_user_t *manager_account)
{
    printf("history_file_init start\n");
    user_t *account_pos=manager_account->head;
    int num=manager_account->num1;
    
    char filename[100][num];
    for (int i = 0; i < 100; i++) 
    {
        for (int j = 0; j < num; j++) 
        {
            filename[i][j] = '0';  // 每个元素赋值为 '0'
        }
    }

    int i=0;
    do
    {
        sprintf(filename[i],"history_%s.txt",account_pos->In_AccountNumber);
        FILE *src_fp;
        src_fp=fopen(filename[i],"a+");
        if(src_fp==NULL)
        {
            perror("historyfile create error!\n");
            return;
        }
        fclose(src_fp);
        
        account_pos=account_pos->next;
        i++;
    }while(account_pos!=manager_account->head && i<num);    
}

// 初始化三级用户配置文件
void on_config_file_init(manager_user_t *manager_account)
{
    printf("config_file_init start\n");
    user_t *account_pos=manager_account->head;
    FILE *dst_fp;
    int i=0;
    char filename[100]={'0'};

    do{
        if(account_pos->accountgrade==3)
        {
            sprintf(filename,"config_%s.txt",account_pos->In_AccountNumber);
            dst_fp=fopen(filename,"a+");
            if(dst_fp==NULL)
            {
                perror("configfile create error!\n");
                return;
            }
            fclose(dst_fp);
        }   

        account_pos=account_pos->next;
        i++;  
    }while(account_pos!=manager_account->head);
}

